﻿using Newtonsoft.Json.Linq;

namespace Newtonsoft.Json
{
    /// <summary>长整形转日期</summary>
    public class LongToDateTimeConverter : JsonConverter<long>
    {
        public override long ReadJson(JsonReader reader, Type objectType, long existingValue, bool hasExistingValue, JsonSerializer serializer)
        {
            var jt = JToken.ReadFrom(reader);
            return jt.Value<long>();
        }

        public override void WriteJson(JsonWriter writer, long value, JsonSerializer serializer)
        {
            serializer.Serialize(writer, value > 0 ? value.ToLocalTime() : null);
        }
    }
}
